package com.guli.sms.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.guli.sms.entity.HomeAdvEntity;
import com.guli.sms.service.HomeAdvService;

import com.guli.common.utils.R;


/**
 * 首页轮播广告
 *
 * @author LuoJunHua
 * @email 1007052116@qq.com
 * @date 2020-11-29 10:59:49
 */
@RestController
@RequestMapping("/sms/homeadv")
public class HomeAdvController {

    @Autowired
    private HomeAdvService homeAdvService;


    @GetMapping("/list/{currentPage}/{size}")
    @ApiOperation("根据当前页和每页显示的记录数来获取homeAdv分页列表")
    public R list(@PathVariable("currentPage") Integer currentPage, @PathVariable("size") Integer size, @RequestParam Map<String, Object> params) {

        Page<HomeAdvEntity> page = homeAdvService.queryPage(currentPage, size, params);

        return R.ok().put("page", page);
    }


    @GetMapping("/info/{id}")
    @ApiOperation("根据id获取HomeAdv")
    public R info(@PathVariable("id") Long id) {

            HomeAdvEntity homeAdv = homeAdvService.getById(id);

        return R.ok().put("homeAdv", homeAdv);
    }

    @PostMapping("/save")
    @ApiOperation("插入HomeAdv")
    public R save(@RequestBody HomeAdvEntity homeAdv) {

            homeAdvService.save(homeAdv);

        return R.ok();
    }

    @PostMapping("/saveBatch")
    @ApiOperation("批量插入HomeAdv")
    @Transactional
    public R saveBatch(@RequestBody List<HomeAdvEntity> homeAdvList) {
            homeAdvService.saveBatch(homeAdvList);

        return R.ok();
    }

    @PostMapping("/update")
    @ApiOperation("根据id更新HomeAdv")
    public R update(@RequestBody HomeAdvEntity homeAdv) {
            homeAdvService.updateById(homeAdv);

        return R.ok();
    }

    @PutMapping("/deleteBatch")
    @ApiOperation("根据id批量删除HomeAdv")
    public R delete(@RequestBody Long[] ids) {
            homeAdvService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
